
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="f" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>超市账单管理系统</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/public.css"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/style.css"/>
</head>
<body>
<!--头部-->
    <header class="publicHeader">
        <h1>超市账单管理系统</h1>
        <div class="publicHeaderR">
            <p><span>下午好！</span><span style="color: #fff21b">${user.userName}</span> , 欢迎你！</p>
            <a href="../../login.jsp">退出</a>
        </div>
    </header>
<!--时间-->
    <section class="publicTime">
        <span id="time">2015年1月1日 11:11  星期一</span>
        <a href="#">温馨提示：为了能正常浏览，请使用高版本浏览器！（IE10+）</a>
    </section>
<!--主体内容-->
    <section class="publicMian ">
        <div class="left">
            <%@include file="left.jsp"%>
        </div>
        <div class="right">
           <%@include file="right.jsp"%>

            <div class="search">
                <form>
                <span>用户名：</span>
                <input type="text" placeholder="请输入用户名"/>
                <input type="submit" value="查询"/>
                <a href="${pageContext.request.contextPath}/page/userAdd">添加用户</a>

                </form>
            </div>
            <!--用户-->
            <table class="providerTable" cellpadding="0" cellspacing="0">
                <tr class="firstTr">
                    <th width="10%">用户编码</th>
                    <th width="20%">用户名称</th>
                    <th width="10%">性别</th>
                    <th width="10%">年龄</th>
                    <th width="10%">电话</th>
                    <th width="10%">用户类型</th>
                    <th width="30%">操作</th>
                </tr>

                <c:forEach items="${userList}" var="user">
                <tr>
                    <td>${user.userCode}</td>
                    <td>${user.userName}</td>
                    <td>${user.gender}</td>
                    <td>
                        <jsp:useBean id="now" class="java.util.Date" scope="page"></jsp:useBean>
                       <f:formatNumber value="${now.year-user.birthday.year}"></f:formatNumber>
                    </td>
                    <td>${user.phone}</td>
                    <td>
                        ${user.role.rolename}
                    </td>
                    <td>
                        <a href="${pageContext.request.contextPath}/user/${user.id}"><img src="${pageContext.request.contextPath}/img/read.png" alt="查看" title="查看"/></a>
                        <a href="${pageContext.request.contextPath}/user/update/${user.id}"><img src="${pageContext.request.contextPath}/img/xiugai.png" alt="修改" title="修改"/></a>
                        <a href="javascript:void(0)" uid="${user.id}"   class="removeUser"><img src="${pageContext.request.contextPath}/img/schu.png" alt="删除" title="删除"/></a>
                    </td>
                </tr>
                </c:forEach>
            </table>

        </div>
    </section>

<!--点击删除按钮后弹出的页面-->
<div class="zhezhao"></div>
<div class="remove" id="removeUse">
    <div class="removerChid">
        <h2>提示</h2>
        <div class="removeMain">
            <p>你确定要删除该用户吗？</p>
            <a href="javascript:void(0)" id="yes">确定</a>
            <a href="#" id="no">取消</a>
        </div>
    </div>
</div>



<script src="${pageContext.request.contextPath}/js/jquery.js"></script>
<script src="${pageContext.request.contextPath}/js/js.js"></script>
<script src="${pageContext.request.contextPath}/js/time.js"></script>
<script type="text/javascript">
    var id;
    var tr;//要删除的tr

        //用户管理页面上点击删除按钮弹出删除框(userList.jsp)
        $(function () {

            $('.removeUser').click(function () {
                //获取当前删除的id
                id=$(this).attr("uid");
                tr=$(this).parent().parent();
                $('.zhezhao').css('display', 'block');
                //fadein：显示
                $('#removeUse').fadeIn();
            });
        });

        $(function () {
            $('#no').click(function () {
                $('.zhezhao').css('display', 'none');
                $('#removeUse').fadeOut();
            });
        });


    $(function () {

        $('#yes').click(function () {

            $.ajax({
                url:"${pageContext.request.contextPath}/user/del",
                type:"post",
                data:{"id":id},//发送到前台的数据（到服务器的数据）
                dataType:"text",//后台返回的数据类型
                success:function (data) {

                   if(data=="true") {
                       //删除当前行
                       tr.remove();
                   }
                }

            });
            //隐藏对话框
            $('.zhezhao').css('display', 'none');
            $('#removeUse').fadeOut();

        });
    });




</script>
</body>
</html>